//
//  GRAddressTableViewCell.m
//  YC_GRice
//
//  Created by luojinrong11 on 2018/7/9.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRAddressTableViewCell.h"
@interface GRAddressTableViewCell()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@property (weak, nonatomic) IBOutlet UILabel *phoneNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UIButton *defaultAddBt;

@end

@implementation GRAddressTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


-(void)setAddressModel:(GRMyAddressEditorModel *)addressModel{
    _addressModel = addressModel;
    self.nameLabel.text = addressModel.consigneeName;
    self.phoneNumLabel.text = addressModel.consigneeMobile;
    self.addressLabel.text = addressModel.addressStr;
    self.defaultAddBt.selected = addressModel.isDefault;
}


- (IBAction)defaultAddressAction:(id)sender {
    if (!self.addressModel.isDefault) {
        if (_delegate && [_delegate respondsToSelector:@selector(setDefaultAdrress:AddressModel:)]) {
            [_delegate setDefaultAdrress:self AddressModel:self.addressModel];
        }
    }
}

- (IBAction)editorAction:(id)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(editorAddress:AddressModel:)]) {
        [_delegate editorAddress:self AddressModel:self.addressModel];
    }
    
}


- (IBAction)deleteAction:(id)sender {
    
    [[LFAlertBox defaultAlert ]showAlertContent:@"删除地址后将无法恢复是否删除地址？" cancle:@"否" sure:@"是" completion:^(NSInteger index) {
        if (index == 1) {
            if (_delegate && [_delegate respondsToSelector:@selector(deleteAddress:AddressModel:)]) {
                [_delegate deleteAddress:self AddressModel:self.addressModel];
            }
        }
    }];
 
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
